package com.codedancer.campus.manager.api.commentReport;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.commentReport.ro.CommentReportDisposeAddRo;
import com.codedancer.campus.manager.api.commentReport.ro.CommentReportPageSearchRo;
import com.codedancer.campus.manager.service.ICommentReportService;
import com.codedancer.campus.manager.service.bo.commentReport.CommentReportDisposeAddBo;
import com.codedancer.campus.manager.service.bo.commentReport.CommentReportPageSearchBo;
import com.codedancer.campus.manager.service.vo.commentReport.CommentReportPageVo;
import com.codedancer.campus.manager.service.vo.commentReport.CommentReportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "评论举报api", description = "评论举报api", tags = "评论举报api")
@RequestMapping("/api/comment-report")
public class CommentReportApi extends BaseApi {

  @Autowired
  private ICommentReportService commentReportService;

  @GetMapping("/page")
  @ApiOperation("分页查询评论举报")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<IPage<CommentReportPageVo>> page(
      @ApiParam(value = "评论举报分页查询Ro", required = false)
      CommentReportPageSearchRo commentReportPageSearchRo) {
    CommentReportPageSearchBo commentReportPageSearchBo = BeanUtil.copyProperties(
        commentReportPageSearchRo, CommentReportPageSearchBo.class);
    return success(commentReportService.page(commentReportPageSearchBo));
  }

  @GetMapping("/detail/{uuid}")
  @ApiOperation("评论举报详情")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<CommentReportVo> detail(
      @PathVariable(value = "uuid", required = true) @ApiParam(value = "评论举报uuid", required = true) String uuid) {
    return success(commentReportService.detail(uuid));
  }

  @PutMapping("/dispose-exists-violation/{uuid}")
  @ApiOperation("处理存在违规")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<Void> disposeExistsViolation(
      @RequestBody @Valid @ApiParam(value = "评论举报处理Ro", required = true)
      CommentReportDisposeAddRo commentReportDisposeAddRo,
      @PathVariable(value = "uuid", required = true) @ApiParam(value = "评论举报uuid", required = true) String uuid) {
    CommentReportDisposeAddBo commentReportDisposeAddBo = BeanUtil.copyProperties(
        commentReportDisposeAddRo, CommentReportDisposeAddBo.class);
    commentReportDisposeAddBo.setCommentReportUuid(uuid);
    commentReportDisposeAddBo.setCurrentUserUuid(currentLoginUuid());
    commentReportService.disposeExistsViolation(commentReportDisposeAddBo);
    return success();
  }

  @PutMapping("/dispose-no-exists-violation/{uuid}")
  @ApiOperation("处理不存在违规")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<Void> disposeNoExistsViolation(
      @RequestBody @Valid @ApiParam(value = "评论举报处理Ro", required = true)
      CommentReportDisposeAddRo commentReportDisposeAddRo,
      @PathVariable(value = "uuid", required = true) @ApiParam(value = "评论举报uuid", required = true) String uuid) {
    CommentReportDisposeAddBo commentReportDisposeAddBo = BeanUtil.copyProperties(
        commentReportDisposeAddRo, CommentReportDisposeAddBo.class);
    commentReportDisposeAddBo.setCommentReportUuid(uuid);
    commentReportDisposeAddBo.setCurrentUserUuid(currentLoginUuid());
    commentReportService.disposeNoExistsViolation(commentReportDisposeAddBo);
    return success();
  }
}
